home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #1 / Amiga Plus CD - 2000 - No. 1.iso / Tools / HD / SmartFileSystem / V1.58 / Sources / Diskspeed / diskspeed.c next >
Encoding:
C/C++ Source or Header  |  1998-10-29  |  25.8 KB  |  1,145 lines

  1. #include <devices/timer.h>
  2. #include <dos/dos.h>
  3. #include <dos/filehandler.h>
  4. #include <exec/io.h>
  5. #include <exec/memory.h>
  6. #include <exec/types.h>
  7. #include <proto/dos.h>
  8. #include <proto/exec.h>
  9. #include <proto/timer.h>
  10. #include <proto/utility.h>
  11.  
  12. #include <m68881.h>
  13. #include <math.h>
  14. #include <stdio.h>
  15.  
  16. struct Library *UtilityBase;
  17. struct Library *TimerBase;
  18. struct MsgPort *msgporttimer;
  19. struct timerequest *iorequesttimer;
  20.  
  21. BPTR maindirlock;
  22. BPTR oldlock;
  23.  
  24. LONG init(void);
  25. LONG cleanup(void);
  26.  
  27. struct EClockVal starttime;
  28. struct EClockVal endtime;
  29. ULONG unit;
  30. ULONG timing;
  31.  
  32. LONG test_seekread(ULONG readsize,ULONG filesize);
  33. LONG test_read(ULONG readsize,ULONG filesize);
  34. LONG test_delayedread(ULONG readsize,ULONG filesize);
  35. LONG test_write(ULONG readsize);
  36. LONG test_stationaryread(ULONG readsize);
  37. LONG test_createfiles(void);
  38. LONG testfiles_createfiles(ULONG filesize);
  39. LONG testfiles_deletefiles(void);
  40. LONG testfiles_dirscan(void);
  41. LONG testfiles_openclose(void);
  42. LONG testfiles_load(void);
  43. LONG testfiles_lockunlock(void);
  44. LONG createtestfiles(ULONG filesize);
  45.  
  46. ULONG rangerandom(ULONG);
  47. extern ULONG __asm RANDOM(register __d0 ULONG);
  48. ULONG rndseed=1;
  49.  
  50. UBYTE string[512];
  51.  
  52. struct {char *dir;
  53.         ULONG all;
  54.         ULONG create;
  55.         ULONG delete;
  56.         ULONG dirscan;
  57.         ULONG openclose;
  58.         ULONG lockunlock;
  59.         ULONG load;
  60.         ULONG read;
  61.         ULONG write;
  62.         ULONG seek;
  63.         LONG *files;
  64.         LONG *createsize;
  65.         LONG *seeksize;
  66.         LONG *readsize;
  67.         LONG *writesize;
  68.         ULONG nounits;
  69.         ULONG verbose;
  70.         ULONG noheader;} arglist={NULL};
  71.  
  72. LONG files=1000;
  73. LONG createsize=128;
  74. LONG seeksize=2048;
  75. LONG readsize=65536;
  76. LONG writesize=65536;
  77.  
  78. //void testrandom(void);
  79.  
  80. void main(void) {
  81.   char template[]="DIRECTORY,ALL/S,CREATE/S,DELETE/S,DIRSCAN/S,OPENCLOSE/S,LOCKUNLOCK/S,LOAD/S,READ/S,WRITE/S,SEEK/S,FILES/N,CREATESIZE/N,SEEKSIZE/N,READSIZE/N,WRITESIZE/N,NOUNITS/S,VERBOSE/S,NOHEADER/S";
  82.   struct RDArgs *readarg;
  83.  
  84.   if((DOSBase=(struct DosLibrary *)OpenLibrary("dos.library",37))!=0) {
  85.  
  86. //    testrandom();
  87.  
  88.     readarg=ReadArgs(template,(LONG *)&arglist,0);
  89.     if(readarg!=0) {
  90.       WORD parametersokay=TRUE;
  91.  
  92.       if(arglist.noheader==0) {
  93.         printf("Diskspeed 1.2 (12 July 1998) - Programmed by John Hendrikx\n\n");
  94.       }
  95.  
  96.       if(arglist.all!=0) {
  97.         arglist.create=-1;
  98.         arglist.delete=-1;
  99.         arglist.dirscan=-1;
  100.         arglist.openclose=-1;
  101.         arglist.lockunlock=-1;
  102.         arglist.load=-1;
  103.         arglist.read=-1;
  104.         arglist.write=-1;
  105.         arglist.seek=-1;
  106.       }
  107.       else if(arglist.delete!=0 || arglist.dirscan!=0 || arglist.openclose!=0 || arglist.lockunlock!=0 || arglist.load!=0) {
  108.         arglist.create=-1;
  109.       }
  110.  
  111.       if(arglist.files!=0) {
  112.         files=*arglist.files;
  113.       }
  114.       if(arglist.createsize!=0) {
  115.         createsize=*arglist.createsize;
  116.       }
  117.       if(arglist.seeksize!=0) {
  118.         seeksize=*arglist.seeksize;
  119.       }
  120.       if(arglist.readsize!=0) {
  121.         readsize=*arglist.readsize;
  122.       }
  123.       if(arglist.writesize!=0) {
  124.         writesize=*arglist.writesize;
  125.       }
  126.  
  127.       if(files<10 || files>50000) {
  128.         parametersokay=FALSE;
  129.         printf("Illegal parameter value: files must be between 10 and 50000\n");
  130.       }
  131.  
  132.       if(createsize<0 || createsize>1024*1024) {
  133.         parametersokay=FALSE;
  134.         printf("Illegal parameter value: CREATESIZE must be between 0 and 1048576 (1 MB)\n");
  135.       }
  136.  
  137.       if(readsize<1 || readsize>1024*1024) {
  138.         parametersokay=FALSE;
  139.         printf("Illegal parameter value: READSIZE must be between 1 and 1048576 (1 MB)\n");
  140.       }
  141.  
  142.       if(writesize<1 || writesize>1024*1024) {
  143.         parametersokay=FALSE;
  144.         printf("Illegal parameter value: WRITESIZE must be between 1 and 1048576 (1 MB)\n");
  145.       }
  146.  
  147.       if(seeksize<1 || seeksize>65536) {
  148.         parametersokay=FALSE;
  149.         printf("Illegal parameter value: SEEKSIZE must be between 1 and 65536 (64 kB)\n");
  150.       }
  151.  
  152.  
  153.       if(parametersokay == TRUE && (UtilityBase=OpenLibrary("utility.library",37))!=0) {
  154.         BPTR newdirlock=0;
  155.  
  156.         if(arglist.dir!=0) {
  157.           newdirlock=Lock(arglist.dir,SHARED_LOCK);
  158.         }
  159.  
  160.         if(arglist.dir==0 || newdirlock!=0) {
  161.  
  162.           if(arglist.dir!=0) {
  163.             newdirlock=CurrentDir(newdirlock);
  164.           }
  165.  
  166.           if((msgporttimer=CreateMsgPort())!=0) {
  167.             if((iorequesttimer=CreateIORequest(msgporttimer,sizeof(struct timerequest)))!=0) {
  168.               if(OpenDevice("timer.device",UNIT_VBLANK,&iorequesttimer->tr_node,0)==0) {
  169.                 struct InfoData id;
  170.                 BPTR lock;
  171.                 UBYTE *s;
  172.                 LONG errorcode=0;
  173.  
  174.                 GetCurrentDirName(string,500);
  175.  
  176.                 s=string;
  177.                 while(*s!=0 && *s++!=':') {
  178.                 }
  179.                 *s=0;
  180.  
  181.                 lock=CurrentDir(0);
  182.                 Info(lock,&id);
  183.                 CurrentDir(lock);
  184.  
  185.                 if(arglist.noheader==0) {
  186.                   printf("Volume %s %ld blocks (%ld MB), %ld bytes per block.\n",string,id.id_NumBlocks,(id.id_NumBlocks*(id.id_BytesPerBlock>>9))>>11,id.id_BytesPerBlock);
  187.                   printf("The volume has %ld buffers and the DosType is 0x%08lx.\n\n",AddBuffers(string,0),id.id_DiskType);
  188.                 }
  189.  
  190.                 TimerBase=(struct Library *)iorequesttimer->tr_node.io_Device;
  191.  
  192.                 init();
  193.  
  194.  
  195.  
  196.                 if(arglist.create!=0 && (errorcode=testfiles_createfiles(createsize))==0) {
  197.                   if(arglist.dirscan!=0 && (errorcode=testfiles_dirscan())!=0) {
  198.                     PrintFault(errorcode,"dirscan test failed");
  199.                   }
  200.  
  201.                   if(arglist.lockunlock!=0 && (errorcode=testfiles_lockunlock())!=0) {
  202.                     PrintFault(errorcode,"lockunlock test failed");
  203.                   }
  204.  
  205.                   if(arglist.openclose!=0 && (errorcode=testfiles_openclose())!=0) {
  206.                     PrintFault(errorcode,"openclose test failed");
  207.                   }
  208.  
  209.                   if(arglist.load!=0 && (errorcode=testfiles_load())!=0) {
  210.                     PrintFault(errorcode,"load test failed");
  211.                   }
  212.  
  213.                   if((errorcode=testfiles_deletefiles())!=0) {
  214.                     PrintFault(errorcode,"deletefiles test failed");
  215.                   }
  216.                 }
  217.                 else {
  218.                   PrintFault(errorcode,"couldn't execute files tests");
  219.                 }
  220.  
  221.  
  222.                 /*
  223.  
  224.                 if((errorcode=testfiles_createfiles(1024))==0) {
  225.                   errorcode=testfiles_lockunlock();
  226.                   if(errorcode!=0) {
  227.                     PrintFault(errorcode,"lockunlock test failed");
  228.                   }
  229.  
  230.                   errorcode=testfiles_openclose();
  231.                   if(errorcode!=0) {
  232.                     PrintFault(errorcode,"openclose test failed");
  233.                   }
  234.  
  235.                   errorcode=testfiles_load();
  236.                   if(errorcode!=0) {
  237.                     PrintFault(errorcode,"openclose test failed");
  238.                   }
  239.  
  240.                   errorcode=testfiles_deletefiles();
  241.                   if(errorcode!=0) {
  242.                     PrintFault(errorcode,"deletefiles test failed");
  243.                   }
  244.                 }
  245.                 else {
  246.                   PrintFault(errorcode,"couldn't execute files tests");
  247.                 }
  248.  
  249.  
  250.  
  251.                 if((errorcode=testfiles_createfiles(8192))==0) {
  252.                   errorcode=testfiles_lockunlock();
  253.                   if(errorcode!=0) {
  254.                     PrintFault(errorcode,"lockunlock test failed");
  255.                   }
  256.  
  257.                   errorcode=testfiles_openclose();
  258.                   if(errorcode!=0) {
  259.                     PrintFault(errorcode,"openclose test failed");
  260.                   }
  261.  
  262.                   errorcode=testfiles_load();
  263.                   if(errorcode!=0) {
  264.                     PrintFault(errorcode,"openclose test failed");
  265.                   }
  266.  
  267.                   errorcode=testfiles_deletefiles();
  268.                   if(errorcode!=0) {
  269.                     PrintFault(errorcode,"deletefiles test failed");
  270.                   }
  271.                 }
  272.                 else {
  273.                   PrintFault(errorcode,"couldn't execute files tests");
  274.                 }
  275.  
  276.                 */
  277.  
  278.                 if(arglist.seek!=0 && (errorcode=test_seekread(seeksize,2*1024*1024))!=0) {
  279.                   PrintFault(errorcode,"seek/read test failed");
  280.                 }
  281.  
  282.  
  283.                 if(arglist.read!=0 && (errorcode=test_read(readsize,2*1024*1024))!=0) {
  284.                   PrintFault(errorcode,"read test failed");
  285.                 }
  286.  
  287.                 /*
  288.  
  289.                 errorcode=test_read(4096,2*1024*1024);
  290.                 if(errorcode!=0) {
  291.                   PrintFault(errorcode,"read test failed");
  292.                 }
  293.  
  294.  
  295.                 errorcode=test_read(32768,2*1024*1024);
  296.                 if(errorcode!=0) {
  297.                   PrintFault(errorcode,"read test failed");
  298.                 }
  299.  
  300.  
  301.                 errorcode=test_read(262144,2*1024*1024);
  302.                 if(errorcode!=0) {
  303.                   PrintFault(errorcode,"read test failed");
  304.                 }
  305.  
  306.                 */
  307.  
  308.                 /*
  309.  
  310.                 errorcode=test_stationaryread(262144);
  311.                 if(errorcode!=0) {
  312.                   PrintFault(errorcode,"stationary read test failed");
  313.                 }
  314.  
  315.                 */
  316.  
  317.                 if(arglist.write!=0 && (errorcode=test_write(writesize))!=0) {
  318.                   PrintFault(errorcode,"write test failed");
  319.                 }
  320.  
  321.                 /*
  322.  
  323.                 errorcode=test_write(4096);
  324.                 if(errorcode!=0) {
  325.                   PrintFault(errorcode,"write test failed");
  326.                 }
  327.  
  328.                 errorcode=test_write(32768);
  329.                 if(errorcode!=0) {
  330.                   PrintFault(errorcode,"write test failed");
  331.                 }
  332.  
  333.                 errorcode=test_write(262144);
  334.                 if(errorcode!=0) {
  335.                   PrintFault(errorcode,"write test failed");
  336.                 }
  337.  
  338.                 */
  339.  
  340.                 cleanup();
  341.  
  342.                 CloseDevice(&iorequesttimer->tr_node);
  343.               }
  344.               DeleteIORequest(iorequesttimer);
  345.             }
  346.             DeleteMsgPort(msgporttimer);
  347.           }
  348.  
  349.           if(arglist.dir!=0) {
  350.             newdirlock=CurrentDir(newdirlock);
  351.           }
  352.         }
  353.         else {
  354.           PutStr("Specified directory couldn't be locked!\n");
  355.         }
  356.         CloseLibrary((struct Library *)UtilityBase);
  357.       }
  358.       FreeArgs(readarg);
  359.     }
  360.     CloseLibrary((struct Library *)DOSBase);
  361.   }
  362. }
  363.  
  364. /*
  365. void testrandom(void) {
  366.   DOUBLE s;
  367.   ULONG totalh=0;
  368.   ULONG totall=0;
  369.   ULONG cnt=1;
  370.   ULONG seed=0,oldseed;
  371.  
  372.   for(;;) {
  373.     s=(((DOUBLE)seed + 7.0) * 257.0);
  374.     s=fmod(s, 2147483647.0);
  375.  
  376.     oldseed=seed;
  377.     if((seed=RANDOM(seed))==0) {
  378.       printf("Duplicate found after %ld randoms, seed was %ld\n",cnt,oldseed);
  379.       break;
  380.     }
  381.  
  382.     if(seed!=(ULONG)s) {
  383.       printf("Seed %ld delivered %ld, while it should be %ld\n",oldseed,seed,(ULONG)s);
  384.       break;
  385.     }
  386.  
  387.     totall+=seed;
  388.     if(totall<seed) {
  389.       totalh++;
  390.     }
  391.  
  392.     if((cnt & 0xFFFFFF)==0) {
  393.       ULONG avg;
  394.  
  395.       avg=(totalh / (cnt>>24))<<8;
  396.       printf("Total: 0x%08lx:%08lx, cnt = %ld, avg = %ld\n",totalh, totall, cnt, avg);
  397.     }
  398.  
  399.     cnt++;
  400.   }
  401. }
  402. */
  403.  
  404. ULONG rangerandom(ULONG range) {
  405.   rndseed=RANDOM(rndseed);
  406.   return(rndseed%range);
  407. }
  408.  
  409.  
  410.  
  411. LONG init() {
  412.   if((maindirlock=CreateDir("_test_directory_"))!=0) {
  413.     oldlock=CurrentDir(maindirlock);
  414.     return(0);
  415.   }
  416.   return(IoErr());
  417. }
  418.  
  419.  
  420.  
  421. LONG cleanup() {
  422.   CurrentDir(oldlock);
  423.   UnLock(maindirlock);
  424.   if(DeleteFile("_test_directory_")==DOSFALSE) {
  425.     return(IoErr());
  426.   }
  427.   return(0);
  428. }
  429.  
  430.  
  431.  
  432. void starttimer(void) {
  433.   Delay(5*50);
  434.  
  435.   rndseed=1;
  436.   unit=ReadEClock(&starttime);
  437. }
  438.  
  439.  
  440.  
  441. LONG finished(void) {
  442.   ULONG diff;
  443.  
  444.   ReadEClock(&endtime);
  445.   diff=endtime.ev_lo-starttime.ev_lo;
  446.  
  447.   if(diff/unit>=8) {
  448.     timing=diff/unit*1000+(diff%unit * 1000)/unit;
  449.     return(TRUE);
  450.   }
  451.   return(FALSE);
  452. }
  453.  
  454.  
  455.  
  456. void endtimer(void) {
  457.   ULONG diff;
  458.  
  459.   ReadEClock(&endtime);
  460.   diff=endtime.ev_lo-starttime.ev_lo;
  461.  
  462.   timing=diff/unit*1000+(diff%unit * 1000)/unit;
  463. }
  464.  
  465.  
  466.  
  467. LONG extendfile(BPTR fh,ULONG bytes) {
  468.   LONG errorcode=0;
  469.   UBYTE *mem;
  470.  
  471.   if((mem=AllocVec(131072,MEMF_CLEAR))!=0) {
  472.     ULONG bytestowrite;
  473.  
  474.     while(bytes>0) {
  475.       bytestowrite=bytes;
  476.       if(bytestowrite>131072) {
  477.         bytestowrite=131072;
  478.       }
  479.  
  480.       if(Write(fh,mem,bytestowrite)!=bytestowrite) {
  481.         errorcode=IoErr();
  482.         break;
  483.       }
  484.  
  485.       bytes-=bytestowrite;
  486.     }
  487.  
  488.     FreeVec(mem);
  489.  
  490.     if(errorcode==0) {
  491.       if(Seek(fh,0,OFFSET_BEGINNING)==-1) {
  492.         errorcode=IoErr();
  493.       }
  494.     }
  495.   }
  496.  
  497.   return(errorcode);
  498. }
  499.  
  500.  
  501.  
  502. LONG deletetestfiles(void) {
  503.   ULONG files2=files+1;
  504.   UBYTE filename[16];
  505.  
  506.   while(--files2>0) {
  507.     sprintf(filename,"tf%06ld.tst",files2);
  508.     filename[12]=0;
  509.     DeleteFile(filename);
  510.   };
  511.  
  512.   return(0);
  513. }
  514.  
  515.  
  516.  
  517. LONG createtestfiles(ULONG filesize) {
  518.   LONG errorcode=0;
  519.   BPTR fh;
  520.   ULONG files2=files+1;
  521.   UBYTE filename[16];
  522.  
  523.   while(--files2>0) {
  524.     sprintf(filename,"tf%06ld.tst",files2);
  525.     filename[12]=0;
  526.  
  527.     if((fh=Open(filename,MODE_NEWFILE))==0) {
  528.       errorcode=IoErr();
  529.       break;
  530.     }
  531.  
  532.     if(filesize!=0) {
  533.       if((errorcode=extendfile(fh,filesize))!=0) {
  534.         Close(fh);
  535.         break;
  536.       }
  537.     }
  538.  
  539.     Close(fh);
  540.   }
  541.  
  542.   if(errorcode!=0) {
  543.     deletetestfiles();
  544.   }
  545.  
  546.   return(errorcode);
  547. }
  548.  
  549.  
  550.  
  551. LONG test_seekread(ULONG readsize,ULONG filesize) {
  552.   LONG errorcode=0;
  553.   UBYTE *mem;
  554.   BPTR fh;
  555.  
  556.   if(filesize<=readsize) {
  557.     return(ERROR_NO_FREE_STORE);
  558.   }
  559.  
  560.   if((mem=AllocVec(readsize,0))!=0) {
  561.     if((fh=Open("seekread.tst",MODE_NEWFILE))!=0) {
  562.       if((errorcode=extendfile(fh,filesize))==0) {
  563.         ULONG seekreads=0;
  564.  
  565.         starttimer();
  566.  
  567.         do {
  568.           if(Seek(fh,rangerandom(filesize-readsize),OFFSET_BEGINNING)==-1) {
  569.             errorcode=IoErr();
  570.             break;
  571.           }
  572.  
  573.           if(Read(fh,mem,readsize)!=readsize) {
  574.             errorcode=IoErr();
  575.             break;
  576.           }
  577.  
  578.           seekreads++;
  579.         } while(finished()==FALSE);
  580.  
  581.         if(errorcode==0) {
  582.           if(arglist.verbose!=0) {
  583.             printf("Seek&Read  : Seeks to random locations in a file of %ld bytes & reads %ld bytes.\n",filesize,readsize);
  584.             printf("             %ld seeks & reads/second (%ld seeks & reads in %ld ms)\n",seekreads*1000/timing,seekreads,timing);
  585.           }
  586.           else {
  587.             printf("Random seek/reads of %5ld bytes in\n",readsize);
  588.             printf("                   %7ld byte file : %5ld",filesize,seekreads*1000/timing);
  589.  
  590.             if(arglist.nounits==0) {
  591.               printf(" times/second");
  592.             }
  593.             printf("\n");
  594.           }
  595.         }
  596.       }
  597.  
  598.       Close(fh);
  599.       DeleteFile("seekread.tst");
  600.     }
  601.     else {
  602.       errorcode=IoErr();
  603.     }
  604.     FreeVec(mem);
  605.   }
  606.   else {
  607.     errorcode=ERROR_NO_FREE_STORE;
  608.   }
  609.  
  610.   return(errorcode);
  611. }
  612.  
  613.  
  614.  
  615. LONG test_read(ULONG readsize,ULONG filesize) {
  616.   LONG errorcode=0;
  617.   UBYTE *mem;
  618.   BPTR fh;
  619.  
  620.   if(filesize<=readsize) {
  621.     return(ERROR_NO_FREE_STORE);
  622.   }
  623.  
  624.   if((mem=AllocVec(readsize,0))!=0) {
  625.     if((fh=Open("read.tst",MODE_NEWFILE))!=0) {
  626.       if((errorcode=extendfile(fh,filesize))==0) {
  627.         ULONG reads=0;
  628.         ULONG offset=0;
  629.  
  630.         starttimer();
  631.  
  632.         do {
  633.           if(Read(fh,mem,readsize)!=readsize) {
  634.             errorcode=IoErr();
  635.             break;
  636.           }
  637.  
  638.           offset+=readsize;
  639.  
  640.           if(offset+readsize>filesize) {
  641.             if(Seek(fh,0,OFFSET_BEGINNING)==-1) {
  642.               errorcode=IoErr();
  643.               break;
  644.             }
  645.             offset=0;
  646.           }
  647.  
  648.           reads++;
  649.         } while(finished()==FALSE);
  650.  
  651.         if(errorcode==0) {
  652.           if(arglist.verbose!=0) {
  653.             printf("Read       : Reads %ld bytes at a time from a file of %ld bytes.\n",readsize,filesize);
  654.             printf("             %ld kB/second (%ld reads in %ld ms)\n",(LONG)((double)reads*1000.0/(double)timing*(double)readsize/1024.0),reads,timing);
  655.           }
  656.           else {
  657.             printf("Read data using %7ld byte buffer  : %5ld",readsize,(LONG)((double)reads*1000.0/(double)timing*(double)readsize/1024.0));
  658.  
  659.             if(arglist.nounits==0) {
  660.               printf(" kB/second");
  661.             }
  662.             printf("\n");
  663.           }
  664.         }
  665.       }
  666.  
  667.       Close(fh);
  668.       DeleteFile("read.tst");
  669.     }
  670.     else {
  671.       errorcode=IoErr();
  672.     }
  673.     FreeVec(mem);
  674.   }
  675.   else {
  676.     errorcode=ERROR_NO_FREE_STORE;
  677.   }
  678.  
  679.   return(errorcode);
  680. }
  681.  
  682.  
  683.  
  684. LONG test_delayedread(ULONG readsize,ULONG filesize) {
  685.   LONG errorcode=0;
  686.   UBYTE *mem;
  687.   BPTR fh;
  688.  
  689.   if(filesize<=readsize) {
  690.     return(ERROR_NO_FREE_STORE);
  691.   }
  692.  
  693.   if((mem=AllocVec(readsize,0))!=0) {
  694.     if((fh=Open("read.tst",MODE_NEWFILE))!=0) {
  695.       if((errorcode=extendfile(fh,filesize))==0) {
  696.         ULONG reads=0;
  697.         ULONG offset=0;
  698.  
  699.         starttimer();
  700.  
  701.         do {
  702.           if(Read(fh,mem,readsize)!=readsize) {
  703.             errorcode=IoErr();
  704.             break;
  705.           }
  706.  
  707.           offset+=readsize;
  708.  
  709.           if(offset+readsize>filesize) {
  710.             if(Seek(fh,0,OFFSET_BEGINNING)==-1) {
  711.               errorcode=IoErr();
  712.               break;
  713.             }
  714.             offset=0;
  715.           }
  716.  
  717.           Delay(25);
  718.  
  719.           reads++;
  720.         } while(finished()==FALSE);
  721.  
  722.         if(errorcode==0) {
  723.           timing-=500*reads;  /* Substract the delays. */
  724.           printf("DelayedRead: Reads %ld bytes at a time from a file of %ld bytes with a 0.5 second delay between reads.\n",readsize,filesize);
  725.           printf("             %ld kB/second (%ld reads in %ld ms)\n",(LONG)((double)reads*1000.0/(double)timing*(double)readsize/1024.0),reads,timing);
  726.         }
  727.       }
  728.  
  729.       Close(fh);
  730.       DeleteFile("read.tst");
  731.     }
  732.     else {
  733.       errorcode=IoErr();
  734.     }
  735.     FreeVec(mem);
  736.   }
  737.   else {
  738.     errorcode=ERROR_NO_FREE_STORE;
  739.   }
  740.  
  741.   return(errorcode);
  742. }
  743.  
  744.  
  745.  
  746. LONG test_stationaryread(ULONG readsize) {
  747.   LONG errorcode=0;
  748.   UBYTE *mem;
  749.   BPTR fh;
  750.  
  751.   if((mem=AllocVec(readsize,0))!=0) {
  752.     if((fh=Open("statread.tst",MODE_NEWFILE))!=0) {
  753.       if((errorcode=extendfile(fh,readsize))==0) {
  754.         ULONG reads=0;
  755.  
  756.         starttimer();
  757.  
  758.         do {
  759.           if(Read(fh,mem,readsize)!=readsize) {
  760.             errorcode=IoErr();
  761.             break;
  762.           }
  763.  
  764.           if(Seek(fh,0,OFFSET_BEGINNING)==-1) {
  765.             errorcode=IoErr();
  766.             break;
  767.           }
  768.  
  769.           reads++;
  770.         } while(finished()==FALSE);
  771.  
  772.         if(errorcode==0) {
  773.           printf("Stat.Read  : Reads the same %ld bytes each time.\n",readsize);
  774.           printf("             %ld kB/second (%ld stationary reads in %ld ms)\n",(LONG)((double)reads*1000.0/(double)timing*(double)readsize/1024.0),reads,timing);
  775.         }
  776.       }
  777.  
  778.       Close(fh);
  779.       DeleteFile("statread.tst");
  780.     }
  781.     else {
  782.       errorcode=IoErr();
  783.     }
  784.     FreeVec(mem);
  785.   }
  786.   else {
  787.     errorcode=ERROR_NO_FREE_STORE;
  788.   }
  789.  
  790.   return(errorcode);
  791. }
  792.  
  793.  
  794.  
  795.  
  796. LONG test_write(ULONG writesize) {
  797.   LONG errorcode=0;
  798.   UBYTE *mem;
  799.   BPTR fh;
  800.  
  801.   if((mem=AllocVec(writesize,0))!=0) {
  802.     if((fh=Open("write.tst",MODE_NEWFILE))!=0) {
  803.       ULONG writes=0;
  804.  
  805.       starttimer();
  806.  
  807.       do {
  808.         if(Write(fh,mem,writesize)!=writesize) {
  809.           errorcode=IoErr();
  810.           break;
  811.         }
  812.  
  813.         writes++;
  814.       } while(finished()==FALSE);
  815.  
  816.       if(errorcode==0) {
  817.         if(arglist.verbose!=0) {
  818.           printf("Write      : Writes %ld bytes at a time to a file.\n",writesize);
  819.           printf("             %ld kB/second (%ld writes in %ld ms)\n",(LONG)((double)writes*1000.0/(double)timing*(double)writesize/1024.0),writes,timing);
  820.         }
  821.         else {
  822.           printf("Write data using %7ld byte buffer : %5ld",writesize,(LONG)((double)writes*1000.0/(double)timing*(double)writesize/1024.0));
  823.  
  824.           if(arglist.nounits==0) {
  825.             printf(" kB/second");
  826.           }
  827.           printf("\n");
  828.         }
  829.       }
  830.  
  831.       Close(fh);
  832.       DeleteFile("write.tst");
  833.     }
  834.     else {
  835.       errorcode=IoErr();
  836.     }
  837.     FreeVec(mem);
  838.   }
  839.   else {
  840.     errorcode=ERROR_NO_FREE_STORE;
  841.   }
  842.  
  843.   return(errorcode);
  844. }
  845.  
  846.  
  847.  
  848. LONG test_createfiles() {
  849.   LONG errorcode=0;
  850.   BPTR fh;
  851.   ULONG files=0;
  852.   UBYTE filename[16];
  853.  
  854.   starttimer();
  855.  
  856.   do {
  857.     sprintf(filename,"cf%06ld.tst",files);
  858.     filename[12]=0;
  859.  
  860.     if((fh=Open(filename,MODE_NEWFILE))==0) {
  861.       errorcode=IoErr();
  862.       break;
  863.     }
  864.  
  865.     Close(fh);
  866.  
  867.     files++;
  868.   } while(finished()==FALSE);
  869.  
  870.   if(errorcode==0) {
  871.     printf("CreateFiles: Creates empty files.\n");
  872.     printf("             %ld files created/second (%ld files created in %ld ms)\n",files*1000/timing,files,timing);
  873.   }
  874.  
  875.   while(files-->0) {
  876.     sprintf(filename,"cf%06ld.tst",files);
  877.     filename[12]=0;
  878.     DeleteFile(filename);
  879.   };
  880.  
  881.   return(errorcode);
  882. }
  883.  
  884.  
  885.  
  886. LONG testfiles_dirscan() {
  887.   struct FileInfoBlock *fib;
  888.   ULONG entries=0;
  889.   LONG errorcode=0;
  890.  
  891.   if((fib=AllocDosObjectTags(DOS_FIB,0))!=0) {
  892.     if(Examine(maindirlock,fib)!=DOSFALSE) {
  893.  
  894.       starttimer();
  895.  
  896.       do {
  897.         if(ExNext(maindirlock,fib)==DOSFALSE) {
  898.           errorcode=IoErr();
  899.           if(errorcode!=ERROR_NO_MORE_ENTRIES) {
  900.             break;
  901.           }
  902.  
  903.           if(Examine(maindirlock,fib)==DOSFALSE) {
  904.             errorcode=IoErr();
  905.             break;
  906.           }
  907.  
  908.           errorcode=0;
  909.         }
  910.  
  911.         entries++;
  912.       } while(finished()==FALSE);
  913.     }
  914.     else {
  915.       errorcode=IoErr();
  916.     }
  917.  
  918.     FreeDosObject(DOS_FIB,fib);
  919.   }
  920.   else {
  921.     errorcode=ERROR_NO_FREE_STORE;
  922.   }
  923.  
  924.   if(errorcode==0) {
  925.     if(arglist.verbose!=0) {
  926.       printf("DirScan    : Scans all files in a directory.\n");
  927.       printf("             %ld files/second (%ld files in %ld ms)\n",entries*1000/timing,entries,timing);
  928.     }
  929.     else {
  930.       printf("Scan all files in a directory        : %5ld",entries*1000/timing);
  931.  
  932.       if(arglist.nounits==0) {
  933.         printf(" files/second");
  934.       }
  935.       printf("\n");
  936.     }
  937.   }
  938.  
  939.   return(errorcode);
  940. }
  941.  
  942.  
  943.  
  944. LONG testfiles_openclose() {
  945.   ULONG openscloses=0;
  946.   LONG errorcode=0;
  947.   UBYTE filename[16];
  948.   BPTR fh;
  949.  
  950.   starttimer();
  951.  
  952.   do {
  953.     sprintf(filename,"tf%06ld.tst",rangerandom(files)+1);
  954.  
  955.     if((fh=Open(filename,MODE_OLDFILE))!=0) {
  956.       Close(fh);
  957.     }
  958.     else {
  959.       errorcode=IoErr();
  960.     }
  961.  
  962.     openscloses++;
  963.   } while(finished()==FALSE);
  964.  
  965.   if(errorcode==0) {
  966.     if(arglist.verbose!=0) {
  967.       printf("Open&Close : Opens a random file and closes it again.\n");
  968.       printf("             %ld opens & closes/second (%ld opens & closes in %ld ms)\n",openscloses*1000/timing,openscloses,timing);
  969.     }
  970.     else {
  971.       printf("Open and close a random file         : %5ld",openscloses*1000/timing);
  972.  
  973.       if(arglist.nounits==0) {
  974.         printf(" files/second");
  975.       }
  976.       printf("\n");
  977.     }
  978.   }
  979.  
  980.   return(errorcode);
  981. }
  982.  
  983.  
  984.  
  985. LONG testfiles_lockunlock() {
  986.   ULONG locksunlocks=0;
  987.   LONG errorcode=0;
  988.   UBYTE filename[16];
  989.   BPTR lock;
  990.  
  991.   starttimer();
  992.  
  993.   do {
  994.     sprintf(filename,"tf%06ld.tst",rangerandom(files)+1);
  995.  
  996.     if((lock=Lock(filename,SHARED_LOCK))!=0) {
  997.       UnLock(lock);
  998.     }
  999.     else {
  1000.       errorcode=IoErr();
  1001.     }
  1002.  
  1003.     locksunlocks++;
  1004.   } while(finished()==FALSE);
  1005.  
  1006.   if(errorcode==0) {
  1007.     if(arglist.verbose!=0) {
  1008.       printf("Lock&Unlock: Locks a random file and unlocks it again.\n");
  1009.       printf("             %ld locks & unlocks/second (%ld locks & unlocks in %ld ms)\n",locksunlocks*1000/timing,locksunlocks,timing);
  1010.     }
  1011.     else {
  1012.       printf("Lock and unlock a random file        : %5ld",locksunlocks*1000/timing);
  1013.  
  1014.       if(arglist.nounits==0) {
  1015.         printf(" files/second");
  1016.       }
  1017.       printf("\n");
  1018.     }
  1019.   }
  1020.  
  1021.   return(errorcode);
  1022. }
  1023.  
  1024.  
  1025.  
  1026. LONG testfiles_deletefiles() {
  1027.  
  1028.   starttimer();
  1029.  
  1030.   deletetestfiles();
  1031.  
  1032.   endtimer();
  1033.  
  1034.   if(arglist.verbose!=0) {
  1035.     printf("DeleteFiles: Deletes %ld files.\n",files);
  1036.     printf("             %ld files deleted/second (%ld files deleted in %ld ms)\n",files*1000/timing,files,timing);
  1037.   }
  1038.   else {
  1039.     printf("Deletes %5ld files                  : %5ld",files,files*1000/timing);
  1040.  
  1041.     if(arglist.nounits==0) {
  1042.       printf(" files/second");
  1043.     }
  1044.     printf("\n");
  1045.   }
  1046.  
  1047.   return(0);
  1048. }
  1049.  
  1050.  
  1051.  
  1052. LONG testfiles_createfiles(ULONG filesize) {
  1053.   LONG errorcode;
  1054.  
  1055.   starttimer();
  1056.  
  1057.   errorcode=createtestfiles(filesize);
  1058.  
  1059.   endtimer();
  1060.  
  1061.   if(errorcode==0) {
  1062.     if(arglist.verbose!=0) {
  1063.       printf("CreateFiles: Creates %ld files of %ld bytes.\n",files,filesize);
  1064.       printf("             %ld files created/second (%ld files created in %ld ms)\n",files*1000/timing,files,timing);
  1065.     }
  1066.     else {
  1067.       printf("Creates %5ld files of %7ld bytes : %5ld",files,filesize,files*1000/timing);
  1068.  
  1069.       if(arglist.nounits==0) {
  1070.         printf(" files/second");
  1071.       }
  1072.       printf("\n");
  1073.     }
  1074.   }
  1075.  
  1076.   return(errorcode);
  1077. }
  1078.  
  1079.  
  1080.  
  1081. LONG testfiles_load() {
  1082.   ULONG loads=0;
  1083.   LONG errorcode=0;
  1084.   UBYTE filename[16];
  1085.   BPTR fh;
  1086.   UBYTE *mem;
  1087.  
  1088.   if((mem=AllocVec(131072,0))!=0) {
  1089.  
  1090.     starttimer();
  1091.  
  1092.     do {
  1093.       sprintf(filename,"tf%06ld.tst",rangerandom(files)+1);
  1094.  
  1095.       if((fh=Open(filename,MODE_OLDFILE))!=0) {
  1096.  
  1097.         while(Read(fh,mem,131072)==131072) {
  1098.         }
  1099.  
  1100.         Close(fh);
  1101.       }
  1102.       else {
  1103.         errorcode=IoErr();
  1104.       }
  1105.  
  1106.       loads++;
  1107.     } while(finished()==FALSE);
  1108.  
  1109.     FreeVec(mem);
  1110.  
  1111.     if(errorcode==0) {
  1112.       if(arglist.verbose!=0) {
  1113.         printf("Load       : Opens a random file, loads it and closes it again.\n");
  1114.         printf("             %ld loads/second (%ld loads in %ld ms)\n",loads*1000/timing,loads,timing);
  1115.       }
  1116.       else {
  1117.         printf("Load a random file                   : %5ld",loads*1000/timing);
  1118.  
  1119.         if(arglist.nounits==0) {
  1120.           printf(" files/second");
  1121.         }
  1122.         printf("\n");
  1123.       }
  1124.     }
  1125.   }
  1126.  
  1127.   return(errorcode);
  1128. }
  1129.  
  1130. /*
  1131.  
  1132. Creates 50000 files of 1048576 bytes : 10000 files/second
  1133. Open and close a random file         : 10000 files/second
  1134. Lock and unlock a random file        : 10000 files/second
  1135. Load a random file                   : 10000 files/second
  1136. Deletes 50000 files                  : 10000 files/second
  1137.  
  1138. Random seek/reads of 65536 bytes in
  1139.                    1048576 byte file : 10000 times/second
  1140.  
  1141. Read data using 1048576 byte buffer  : 10000 kB/second
  1142. Write data using 1048576 byte buffer : 10000 kB/second
  1143.  
  1144. */
  1145.